package com.edais.service.imp;

import com.edais.dao.*;
import com.edais.domain.*;
import com.edais.domain.zftPay.FastPayTokenParamters;
import com.edais.domain.zftPay.PayParamtersTemp;
import com.edais.service.RateRisesCouponsService;
import com.edais.service.SMSService;
import com.edais.service.UserCardService;
import com.edais.util.CommonUtil;
import com.edais.util.Consts;
import com.edais.util.JsonUtil;
import com.edais.util.Message;
import com.edais.util.llpay.LLPayThridPartyFunctionUtil;
import com.edais.util.zsht.ZSHTPayThridPartyFunctionUtil;
import com.yunzhi.domain.ResultCode;
import com.yunzhi.domain.ResultDTO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@Service

public class UserCardServiceImpl implements UserCardService {

	private static final Log logger = LogFactory.getLog(UserCardServiceImpl.class);

	@Autowired
	private UserCardDao userCardDao;

	@Autowired
	private CenterDao centerDao;

	@Autowired
	private PayDao payDao;

	@Autowired
	private UserDao userDao;

	@Autowired
	private AssetsDao assetsDao;

	@Autowired
	private RateRisesCouponsService rateRisesCouponsService;

	@Autowired
	private SMSService sMSService;

	@Autowired
	private UserExtractInfoDao userExtractInfoDao;

	/**
	 * 根据用户ID查询用户绑定银行卡信息
	 */
	@Override
	public Map<String, Object> queryUserCardInfoByUserId(Map<String, Object> requestMap) {
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		List<UserRecePayCard> userCardInfo = this.userCardDao.queryUserCardInfoByUserId(requestMap);
		if (userCardInfo == null) {
			userCardInfo = new ArrayList<UserRecePayCard>();
		}
		rtnMap.put("userCardInfo", userCardInfo);
		rtnMap.put("rescode", Consts.SUCCESS_CODE);
		rtnMap.put("resmsg", Consts.SUCCESS_DESCRIBE);
		rtnMap.put("resmsg_cn", "");
		rtnMap.put("userCardInfoCount", userCardInfo.size());

		return rtnMap;
	}

	/**
	 * 获取列表
	 */
	@Override
	public List<UserRecePayCard> queryUserCardListInfoByUserId(Map<String, Object> requestMap) {

		List<UserRecePayCard> userCardInfo = this.userCardDao.queryUserCardInfoByUserId(requestMap);
		if (userCardInfo == null) {
			userCardInfo = new ArrayList<UserRecePayCard>();
		}
		return userCardInfo;
	}

	/**
	 * 连连支付-查询银行卡卡bin
	 */
	@Override
	public Map<String, String> queryCardBinLL(Map<String, String> requestMap) {

		Map<String, String> bankCardQueryResult = new HashMap<String, String>();

		bankCardQueryResult = LLPayThridPartyFunctionUtil.bankCardQuery(requestMap);

		if (bankCardQueryResult == null || "sysException".equals(bankCardQueryResult.get("rescode"))) {
			throw new RuntimeException("查询银行卡卡bin失败");
		} else if ("BusinessException".equals(bankCardQueryResult.get("rescode"))) {
			throw new RuntimeException(String.valueOf(bankCardQueryResult.get("resmsg_cn")));
		}

		return bankCardQueryResult;
	}

	/**
	 * 连连支付-查询用户签约信息
	 */
	@Override
	public Map<String, String> queryUserSignInfo(Map<String, String> requestMap) {
		Map<String, String> userBankCardResult = new HashMap<String, String>();

		userBankCardResult = LLPayThridPartyFunctionUtil.userBankCard(requestMap);
		if (userBankCardResult == null || "sysException".equals(userBankCardResult.get("rescode"))) {
			throw new RuntimeException("查询用户签约信息失败");
		} else if ("BusinessException".equals(userBankCardResult.get("rescode"))) {
			throw new RuntimeException(String.valueOf(userBankCardResult.get("resmsg_cn")));
		}

		return userBankCardResult;
	}

	/**
	 * 保存用户银行卡信息
	 * 
	 * @throws Exception
	 * @throws NumberFormatException
	 * @throws PaypalmException
	 */
	@Override
	public Map<String, String> saveUserBankCardInfo(Map<String, String> requestMap)
			throws NumberFormatException, Exception {
		Map<String, String> returnMap = new HashMap<String, String>();
		String userId = requestMap.get("userId");
		String cardNumber = requestMap.get("cardNo");
		String bankCode = requestMap.get("bankCode");
		String bankName = requestMap.get("bankName");
		String bindindReqNum = requestMap.get("bindindReqNum");
		String acctName = requestMap.get("acctName");
		String idCard = requestMap.get("idCard");
		String cardPhone = requestMap.get("cardPhone");

		// 查询是否存在当前银行卡
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", userId);
		paramMap.put("cardNumber", cardNumber);

		UserRecePayCard userRecePayCard = userCardDao.queryBankCardByCardNo(paramMap);
		/**
		 * 如果存在银行卡则进行更新操作 不存在银行卡进行保存操作
		 */
		paramMap.put("bankCode", bankCode);
		Bank bank = userCardDao.queryBankInfoByBankCode(paramMap);

		// 鉴权通道(掌上汇通)
		/*
		 * if(bank.getPay_platform_id().equals("2")){
		 * 
		 * //判断当日鉴权是否超过3次
		 * 
		 * 
		 * Map<String,Object> checkBankRtnMap =
		 * zshtBankCardAndPhoneCheck(Long.parseLong(userId),cardNumber,
		 * acctName, idCard, cardPhone); String checkFlag =
		 * checkBankRtnMap.get("checkFlag").toString();
		 * if(checkFlag.equals("N")){ returnMap.put("rescode",
		 * Consts.CHECK_CODE); returnMap.put("resmsg",
		 * checkBankRtnMap.get("checkDesc").toString()); return returnMap; } }
		 */

		Integer bankId = bank.getId();
		bankName = bank.getBank_name();
		if (userRecePayCard == null) {
			userRecePayCard = new UserRecePayCard();
			userRecePayCard.setUser_id(Integer.parseInt(userId));
			userRecePayCard.setCard_number(cardNumber);
			// 查询银行信息进行保存
			userRecePayCard.setBank_id(bankId);
			userRecePayCard.setBank_name(bankName);
			userRecePayCard.setIs_valid('N');
			userRecePayCard.setIs_binding('N');
			userRecePayCard.setCreate_time(new Date());
			userRecePayCard.setCreate_per(userId);
			userRecePayCard.setAccount_name(acctName);
			userRecePayCard.setReceive_certificate_type(1);
			userRecePayCard.setReceive_certificate_no(idCard);
			userRecePayCard.setMedia_type(1);
			userRecePayCard.setBinding_req_num(bindindReqNum);
			userRecePayCard.setPhone_no(StringUtils.isNotBlank(cardPhone) ? cardPhone : "");
			// 保存银行卡信息
			try {
				userCardDao.saveUserBankCardInfo(userRecePayCard);
				returnMap.put("rescode", Consts.SUCCESS_CODE);
				returnMap.put("resmsg", Consts.SUCCESS_DESCRIBE);
			} catch (Exception e) {
				returnMap.put("rescode", Consts.ERROR_CODE);
				returnMap.put("resmsg", e.getMessage());
			}
		} else {
			// 查询银行信息进行保存
			userRecePayCard.setBank_id(bankId);
			userRecePayCard.setBank_name(bankName);
			userRecePayCard.setIs_valid('N');
			userRecePayCard.setIs_binding('N');
			userRecePayCard.setUpdate_per(userId);
			userRecePayCard.setAccount_name(acctName);
			userRecePayCard.setReceive_certificate_no(idCard);
			userRecePayCard.setBinding_req_num(bindindReqNum);

			// 更新信息
			try {
				userCardDao.updateUserBankCardInfo(userRecePayCard);
				returnMap.put("rescode", Consts.SUCCESS_CODE);
				returnMap.put("resmsg", Consts.SUCCESS_DESCRIBE);
			} catch (Exception e) {
				returnMap.put("rescode", Consts.ERROR_CODE);
				returnMap.put("resmsg", e.getMessage());
			}
		}
		return returnMap;
	}

	/**
	 * 充值后更新用户信息（充值回调）
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = false)
	@Override
	public Map<String, Object> updateUserBankCardByReqNum(Map<String, Object> requestMap) throws Exception {
		Map<String, Object> rtnMap = new HashMap<String, Object>();

		String bindingReqNum = requestMap.get("bindingReqNum").toString();
		String payFlag = requestMap.get("payFlay") == null ? null : requestMap.get("payFlay").toString();
		logger.info("bindingReqNum:" + bindingReqNum);
		OrderFormRecharge isFalgFormRecharge = null;
		isFalgFormRecharge = centerDao.selectOrderFromRechargeByOrderId(bindingReqNum);
		Integer userId = isFalgFormRecharge.getUser_id();
		requestMap.put("userId", userId);
		rtnMap.put("userId", userId);

		String noAgree = requestMap.get("noAgree").toString();
		String moneyOrder = requestMap.get("moneyOrder").toString();
		String oidPayBill = requestMap.get("oidPayBill").toString();
		String reqStr = requestMap.get("reqStr").toString();

		if (!"wy".equals(payFlag)) {
			String cardNumber = isFalgFormRecharge.getCardNumber();
			requestMap.put("cardNumber", cardNumber);

			// 根据user_id查询用户最新更新的银行卡信息
			UserRecePayCard userRecePayCard = null;
			userRecePayCard = this.userCardDao.queryBankCardByCardNo(requestMap);

			if (userRecePayCard != null) {
				userRecePayCard.setBinding_req_num(bindingReqNum);
				userRecePayCard.setLlpay_no_agree(noAgree);
				userRecePayCard.setLlpay_oid_paybill(oidPayBill);
				userRecePayCard.setIs_binding('Y');
				userRecePayCard.setIs_valid('Y');
				userRecePayCard.setUpdate_per(String.valueOf(userId));

				// 更新银行卡信息
				this.userCardDao.updateUserBankCardInfoById(userRecePayCard);
			}
		}
		// 更新临时表订单信息
		OrderFormRecharge orderFormRecharge = new OrderFormRecharge();
		orderFormRecharge.setOrderform_id(bindingReqNum);
		orderFormRecharge.setOrder_id(oidPayBill);
		orderFormRecharge.setBack_time(new Date());// 反馈时间
		orderFormRecharge.setUpdate_time(new Date()); // 更新时间
		orderFormRecharge.setReceive_message(reqStr);// 返回报文
		orderFormRecharge.setBack_commen("连连支付-支付成功");// 反馈描述
		orderFormRecharge.setCore_status("CORE_PROC");// 核心更新为充值处理中

		orderFormRecharge.setRecharge_orderform_status("TRADE_SUCCESS");// 订单状态

		// 查询订单判断是否已经充值成功selectOrderFromRechargeByOrderId
		if (isFalgFormRecharge.getRecharge_orderform_status().equals("TRADE_SUCCESS")) {
			rtnMap.put("rescode", Consts.SUCCESS_CODE);
			rtnMap.put("resmsg", "此订单已更新回调成功。");
		} else {
			int count = centerDao.updateOrderFromRecharge(orderFormRecharge);
			if (count == 0) {
				rtnMap.put("rescode", Consts.SUCCESS_CODE);
				rtnMap.put("resmsg", "未找到订单或此订单已更新回调成功。");
				logger.info("=============未找到订单或此订单已更新回调成功。===============");
				return rtnMap;
			}

			// 判断核心是否回调成功
			if (isFalgFormRecharge.getCore_status().equals("CORE_SUC")) {
				rtnMap.put("rescode", Consts.SUCCESS_CODE);
				rtnMap.put("resmsg", "用户订单核心回调已成功。");
				logger.info("=============用户订单核心回调已成功。===============");
				return rtnMap;
			} else {
				// 更新主账户信息
				String transCode = "E330032";
				Map<String, Object> coreMap = new HashMap<String, Object>();
				coreMap.put("moneyOrder", moneyOrder);
				coreMap.put("userId", userId);
				coreMap.put("applyId", isFalgFormRecharge.getId());
				// 构建json字符串
				String jsonStr;
				jsonStr = CommonUtil.constructJsonStr(transCode, null, coreMap);
				String rtnStr = CommonUtil.getCoreValue(jsonStr);
				JSONObject jsonObject = null;

				try {
					// 如果核心访问失败 返回连连成功（不需要连连继续回调）
					jsonObject = JSONObject.fromObject(rtnStr);
				} catch (Exception e) {
					rtnMap.put("userId", userId);
					rtnMap.put("rescode", Consts.SUCCESS_CODE);
					rtnMap.put("resmsg", Consts.SUCCESS_DESCRIBE);
					return rtnMap;
				}
				String rescode = jsonObject.getString("rescode");
				if (rescode.equals(Consts.SUCCESS_CODE)) {
					rtnMap.put("rescode", Consts.SUCCESS_CODE);
					rtnMap.put("resmsg", Consts.SUCCESS_DESCRIBE);
					// 更新充值订单表核心状态为成功
					orderFormRecharge.setCore_status("CORE_SUC");
					orderFormRecharge.setUpdate_time(new Date());
					centerDao.updateOrderFromRechargeCoreStatus(orderFormRecharge);
				} else {
					logger.info("更新用户主账户失败！");
					throw new Exception("更新用户主账户信息失败！");
				}
			}

		}
		// ouyy 发送短信需要取得userId
		rtnMap.put("userId", userId);
		return rtnMap;
	}

	/**
	 * 更新已绑定银行卡的请求号信息
	 * 
	 * @throws Exception
	 */
	@Override
	public Map<String, Object> updateUserBindindBankCardInfo(Map<String, Object> requestMap) throws Exception {
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		UserRecePayCard userRecePayCard = this.userCardDao.queryBankCardByCardNo(requestMap);
		String bindingReqNum = requestMap.get("bindingReqNum").toString();
		String cardPhone = requestMap.get("cardPhone") == null ? "" : requestMap.get("cardPhone").toString();
		userRecePayCard.setBinding_req_num(bindingReqNum);
		userRecePayCard.setPhone_no(cardPhone);

		Map<String, Object> paramMap = new HashMap<String, Object>();
		// 鉴权通道
		paramMap.put("bankId", userRecePayCard.getBank_id());
		Bank bank = userCardDao.queryBankInfoByBankCode(paramMap);

		/*
		 * //鉴权通道(掌上汇通) if(bank.getPay_platform_id().equals("2")){
		 * 
		 * UserInfo userInfo =
		 * this.userDao.getUserInfo(String.valueOf(userRecePayCard.getUser_id())
		 * ); Map<String,Object> checkBankRtnMap =
		 * zshtBankCardAndPhoneCheck(Long.parseLong(String.valueOf(
		 * userRecePayCard.getUser_id())),userRecePayCard.getCard_number(),
		 * userInfo.getReal_name(), userInfo.getId_card(), cardPhone); String
		 * checkFlag = checkBankRtnMap.get("checkFlag").toString();
		 * if(checkFlag.equals("N")){ rtnMap.put("rescode", Consts.CHECK_CODE);
		 * rtnMap.put("resmsg", checkBankRtnMap.get("checkDesc").toString());
		 * return rtnMap; } }
		 */
		try {
			this.userCardDao.updateUserBindindBankCardInfo(userRecePayCard);
			rtnMap.put("rescode", Consts.SUCCESS_CODE);
			rtnMap.put("resmsg", Consts.SUCCESS_DESCRIBE);
		} catch (Exception e) {
			rtnMap.put("rescode", Consts.ERROR_CODE);
			rtnMap.put("resmsg", e.getMessage());
		}

		return rtnMap;
	}

	/**
	 * 保存连连支付订单信息
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = false)
	@Override
	public Map<String, Object> dealLLPayFastPayToken(Map<String, Object> requestMap) {
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		String moneyOrder = requestMap.get("moneyOrder").toString();
		String userId = requestMap.get("userId").toString();
		// 获取交易流水号
		String orderId = requestMap.get("noOrder").toString();
		String oidPartner = requestMap.get("oidPartner").toString();
		String dtOrder = requestMap.get("dtOrder").toString();
		String rechargeChannel = requestMap.get("rechargeChannel").toString();
		String cardNumber = requestMap.get("cardNumber").toString();
		String platform = requestMap.get("platform").toString();// "LIANLIANPAY";
		try {
			// 拼接字符串
			String paramStr = requestMap.get("signSrc").toString();
			// 充值订单生成
			OrderFormRecharge orderFormRecharge = new OrderFormRecharge();

			orderFormRecharge.setAmount(new BigDecimal(moneyOrder));// 订单金额
			orderFormRecharge.setOrderform_id(orderId);// 订单号
			orderFormRecharge.setRecharge_orderform_status("WAIT_BUYER_PAY");// 等待付款
			orderFormRecharge.setUser_id(Integer.parseInt(userId));// 所属用户
			orderFormRecharge.setSend_message(paramStr);// 上送报文
			orderFormRecharge.setRechargetype("01");// 理财人类型
			orderFormRecharge.setAccounttype("01");// 个人主账户
			orderFormRecharge.setCore_status("CORE_WAIT");// 未调用核心，初始化状态
			// orderFormRecharge.setRecharge_channel("MOBILE"); //
			// 充值渠道（WEB:网站;MOBILE:移动端）
			orderFormRecharge.setRecharge_platform(platform);// 充值平台（UPAY:U付;SINAPAY:新浪支付;LIANLIANPAY:连连支付）
			orderFormRecharge.setSysuserid(Integer.parseInt(userId));// 操作员
			orderFormRecharge.setRecharge_channel(rechargeChannel);// 充值渠道
			orderFormRecharge.setCardNumber(cardNumber);

			centerDao.createRechargeOrder(orderFormRecharge);

			// 购买参数表设置
			FastPayTokenParamters fastPayTokenParamters = new FastPayTokenParamters();
			fastPayTokenParamters.setTradeOrderId(orderId);
			fastPayTokenParamters.setMerNo(oidPartner);
			fastPayTokenParamters.setTrDt(dtOrder);
			fastPayTokenParamters.setBuyAmount(moneyOrder);
			String paramterJson = JsonUtil.getJsonStringFromObject(fastPayTokenParamters);

			PayParamtersTemp paramtersBean = new PayParamtersTemp();
			paramtersBean.setCreate_per(userId);
			paramtersBean.setParameter_str(paramterJson);
			paramtersBean.setPlatform_en_name(platform);
			paramtersBean.setReq_orderid(orderId);
			paramtersBean.setUpdate_per(userId);

			payDao.addPayParameter(paramtersBean);

			rtnMap.put("rescode", Consts.SUCCESS_CODE);
			rtnMap.put("resmsg", Consts.SUCCESS_DESCRIBE);
		} catch (Exception e) {
			rtnMap.put("rescode", Consts.ERROR_CODE);
			rtnMap.put("resmsg", e.getMessage());
		}
		return rtnMap;
	}

	/**
	 * 连连支付提现回调
	 * resultPay支付结果,noOrder，moneyOrder，dtOrder，oidPaybill，settleDate，errorFlag
	 */
	@Override
	public Map<String, Object> llpayWithdrawalsNotify(Map<String, Object> requestMap) {

		Map<String, Object> rtnMap = new HashMap<String, Object>();
		String logInfo = "extractNotify" + requestMap.get("noOrder") + "-";
		String transCode = "E300054";
		String jsonStr;
		try {
			jsonStr = CommonUtil.constructJsonStr(transCode, null, requestMap);
			String rtnStr = CommonUtil.getCoreValue(jsonStr);
			JSONObject jsonObject = JSONObject.fromObject(rtnStr);
			String rescode = jsonObject.getString("rescode");
			String userId = jsonObject.getString("userId");
			User user = this.userDao.getUserDetail(userId);
			if (rescode.equals(Consts.SUCCESS_CODE)) {
				rtnMap.put("rescode", Consts.SUCCESS_CODE);
				rtnMap.put("resmsg", Consts.SUCCESS_DESCRIBE);
				rtnMap.put("userId", userId);
				// 成功给用户发送短信
				String extractAmount = jsonObject.getString("extractAmount");
				String realAmount = jsonObject.getString("realAmount");
				String extractFee = jsonObject.getString("extractFee");
				UserInfo userInfo = this.userDao.getUserInfo(userId);
				sMSService.sendSMS(logInfo, user.getMobile(), "sms05001", userInfo.getReal_name(), extractAmount, extractFee, realAmount);
				String smsNo = "sms05001";// 提现,config_sms表中参数,
				String[] smsParams = { "", extractAmount, extractFee, realAmount };
				Map<String, Object> paramMap = new HashMap<String, Object>();
				paramMap.put("userId", userId);
				paramMap.put("mobile", user.getMobile());
				paramMap.put("title", "提现成功通知");// 标题
				paramMap.put("messageDetailTypeNew", "5");// 1.订制商品个人消息，2.还款成功，3.充值，4.投资，5,提现
				paramMap.put("messageDetailResult", "0");// 0.执行成功消息提示，1.执行失败提示
				paramMap.put("smsParams", smsParams);// 消息模板里需要替换的变量
				paramMap.put("smsNo", smsNo);
				sMSService.sendGetuiMSG(paramMap);
				// 判断如果是特定的code 则不需要发送短信
			} else if (rescode.equals("99998")) {
				UserExtractInfo userExtractInfo = new UserExtractInfo();
				userExtractInfo.setUserId(Integer.valueOf(userId));
				userExtractInfo.setExtractAmount(new BigDecimal(jsonObject.getString("extractAmount")));
				if ("2".equals(jsonObject.getString("extractType"))) {
					// add by aohujun start
					int result = userExtractInfoDao.returnQuickUserExtractInfo(userExtractInfo);
					logger.info(logInfo + "快速提现失败回调，退还提现次数及金额：" + result);
					// add by aohujun end
				}
				if ("1".equals(jsonObject.getString("extractType"))) {
					int result = userExtractInfoDao.returnNormalUserExtractInfo(userExtractInfo);
					logger.info(logInfo + "普通提现失败回调，退还提现次数及金额：" + result);
				}
				String errorFlag = requestMap.get("errorFlag") == null ? "" : requestMap.get("errorFlag").toString();
				if (StringUtils.isNotBlank(errorFlag)) {
					sMSService.sendSMS(logInfo, user.getMobile(), "sms05003", "");
				}
				rtnMap.put("rescode", "99998");
				rtnMap.put("resmsg", "提现失败！");
			} else if (rescode.equals("99997")) {
				logger.info(logInfo + "快速提现回调，已回调");
				String resultPay = requestMap.get("resultPay").toString();
				String noOrder = requestMap.get("noOrder").toString();
				if (resultPay.equals("CANCEL")) {
					logger.error(logInfo + "连连先通知提现成功，后通知提现失败，发送短信给运营处理：" + noOrder);
					sMSService.sendErrorMessageForSystem("sms01002", noOrder);
				}
				rtnMap.put("rescode", "99997");
				rtnMap.put("resmsg", "订单已回调成功！");
			} else {
				rtnMap.put("rescode", Consts.ERROR_CODE);
				rtnMap.put("resmsg", "提现回调更新信息失败！");
			}
		} catch (Exception e) {
			rtnMap.put("rescode", Consts.ERROR_CODE);
			rtnMap.put("resmsg", e.getMessage());
			rtnMap.put("userId", "");
		}
		return rtnMap;
	}

	/**
	 * 富友提现回调
	 * resultPay（SUCCESS成功，FAILD失败）,noOrder上送,oidPaybill返回
	 */
	@Override
	public Map<String, Object> fuyouWithdrawalsNotify(Map<String, Object> requestMap) {

		Map<String, Object> rtnMap = new HashMap<String, Object>();
		String logInfo = "FuyouExtractNotify" + requestMap.get("noOrder") + "-";
		String transCode = "E300054";
		String jsonStr;
		try {
			jsonStr = CommonUtil.constructJsonStr(transCode, null, requestMap);
			String rtnStr = CommonUtil.getCoreValue(jsonStr);
			JSONObject jsonObject = JSONObject.fromObject(rtnStr);
			String rescode = jsonObject.getString("rescode");
			String userId = jsonObject.getString("userId");
			User user = this.userDao.getUserDetail(userId);
			if (rescode.equals(Consts.SUCCESS_CODE)) {
				rtnMap.put("rescode", Consts.SUCCESS_CODE);
				rtnMap.put("resmsg", Consts.SUCCESS_DESCRIBE);
				rtnMap.put("userId", userId);
				// 成功给用户发送短信
				String extractAmount = jsonObject.getString("extractAmount");
				String realAmount = jsonObject.getString("realAmount");
				String extractFee = jsonObject.getString("extractFee");
				UserInfo userInfo = this.userDao.getUserInfo(userId);
				sMSService.sendSMS(logInfo, user.getMobile(), "sms05001", userInfo.getReal_name(), extractAmount, extractFee, realAmount);
				String smsNo = "sms05001";// 提现,config_sms表中参数,
				String[] smsParams = { "", extractAmount, extractFee, realAmount };
				Map<String, Object> paramMap = new HashMap<String, Object>();
				paramMap.put("userId", userId);
				paramMap.put("mobile", user.getMobile());
				paramMap.put("title", "提现成功通知");// 标题
				paramMap.put("messageDetailTypeNew", "5");// 1.订制商品个人消息，2.还款成功，3.充值，4.投资，5,提现
				paramMap.put("messageDetailResult", "0");// 0.执行成功消息提示，1.执行失败提示
				paramMap.put("smsParams", smsParams);// 消息模板里需要替换的变量
				paramMap.put("smsNo", smsNo);
				sMSService.sendGetuiMSG(paramMap);
				// 判断如果是特定的code 则不需要发送短信
			} else if (rescode.equals("99998")) {
				if ("2".equals(jsonObject.getString("extractType"))) {
					// add by aohujun start
					Map<String, Object> param = new HashMap<String, Object>();
					param.put("userId", Long.valueOf(userId));
					int result = userCardDao.updateUserDaysQuickCountIncrease(param);
					logger.info(logInfo + "快速提现失败回调，退还快速提现次数：" + result);
					// add by aohujun end
				}
				String errorFlag = requestMap.get("errorFlag") == null ? "" : requestMap.get("errorFlag").toString();
				if (StringUtils.isNotBlank(errorFlag)) {
					sMSService.sendSMS(logInfo, user.getMobile(), "sms05003", "");
				}
				rtnMap.put("rescode", "99998");
				rtnMap.put("resmsg", "提现失败！");
			} else if (rescode.equals("99997")) {
				logger.info(logInfo + "快速提现回调，已回调");
				String resultPay = requestMap.get("resultPay").toString();
				String noOrder = requestMap.get("noOrder").toString();
				if (resultPay.equals("CANCEL")) {
					logger.error(logInfo + "连连先通知提现成功，后通知提现失败，发送短信给运营处理：" + noOrder);
					sMSService.sendErrorMessageForSystem("sms01002", noOrder);
				}
				rtnMap.put("rescode", "99997");
				rtnMap.put("resmsg", "订单已回调成功！");
			} else {
				rtnMap.put("rescode", Consts.ERROR_CODE);
				rtnMap.put("resmsg", "提现回调更新信息失败！");
			}
		} catch (Exception e) {
			rtnMap.put("rescode", Consts.ERROR_CODE);
			rtnMap.put("resmsg", e.getMessage());
			rtnMap.put("userId", "");
		}
		return rtnMap;
	}

	/**
	 * 订单失败之后更新订单状态
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = false)
	@Override
	public Map<String, Object> updateFailTopUpOrder(Map<String, Object> requestMap) {
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		String userId = requestMap.get("userId").toString();
		// 根据用户ID查询最新的一条充值订单数据
		OrderFormRecharge newestOrder = centerDao.getUserNewestOrderForm(requestMap);
		// 根据最新的订单支付ID查询订单时间(dtOrder)
		String noOrder = newestOrder.getOrderform_id();
		String platform_en_name = "LIANLIANPAY";

		Map<String, String> paramTempMap = new HashMap<String, String>();
		paramTempMap.put("platform_en_name", platform_en_name);
		paramTempMap.put("orderId", noOrder);

		try {
			PayParamtersTemp paramterTemp = payDao.getPayParameter(paramTempMap);
			JSONObject payParamJson = JSONObject.fromObject(paramterTemp);
			JSONObject paramStrJson = JSONObject.fromObject(payParamJson.getString("parameter_str"));
			String dtOrder = paramStrJson.getString("trDt");
			paramTempMap.put("noOrder", noOrder);
			paramTempMap.put("dtOrder", dtOrder);
			// 调用第三方查询支付结果
			Map<String, String> orderQueryMap = LLPayThridPartyFunctionUtil.orderQuery(paramTempMap);
			String rescode = orderQueryMap.get("rescode");
			String resultPay = orderQueryMap.get("resultPay");
			// 判断支付状态
			System.out.println("连连查询订单返回码：" + rescode);
			if (rescode.equals("0000")) {
				String oidPayBill = orderQueryMap.get("oidPayBill");
				if (!resultPay.equals("SUCCESS")) {
					// 修改订单状态为失败
					// 更新临时表订单信息
					OrderFormRecharge orderFormRecharge = new OrderFormRecharge();
					orderFormRecharge.setOrderform_id(noOrder);
					// orderFormRecharge.setOrder_id(oidPayBill);
					orderFormRecharge.setBack_time(new Date());// 反馈时间
					orderFormRecharge.setUpdate_time(new Date()); // 更新时间
					orderFormRecharge.setReceive_message(null);// 返回报文
					orderFormRecharge.setBack_commen("连连支付-支付失败");// 反馈描述
					orderFormRecharge.setCore_status("CORE_FAIL");

					orderFormRecharge.setRecharge_orderform_status("TRADE_FAIL");// 订单状态

					OrderFormRecharge isFalgFormRecharge;
					isFalgFormRecharge = centerDao.selectOrderFromRechargeByOrderId(noOrder);
					System.out.println(isFalgFormRecharge.getRecharge_orderform_status());
					if (isFalgFormRecharge.getRecharge_orderform_status().equals("TRADE_SUCCESS")) {
						rtnMap.put("rescode", Consts.SUCCESS_CODE);
						rtnMap.put("resmsg", "此订单已更新回调成功。");
					} else {
						System.out.println("==================BEGIN UPDATE===================");
						centerDao.updateOrderFromRecharge(orderFormRecharge);
					}
				} else {
					/*
					 * String reqStr = orderQueryMap.get("reqStr"); String
					 * moneyOrder = orderQueryMap.get("moneyOrder"); //
					 * 已经支付成功则更新订单状态 OrderFormRecharge orderFormRecharge = new
					 * OrderFormRecharge();
					 * orderFormRecharge.setOrderform_id(noOrder);
					 * orderFormRecharge.setOrder_id(oidPayBill);
					 * orderFormRecharge.setBack_time(new Date());// 反馈时间
					 * orderFormRecharge.setUpdate_time(new Date()); // 更新时间
					 * orderFormRecharge.setReceive_message(reqStr);// 返回报文
					 * orderFormRecharge.setBack_commen("连连支付-支付成功");// 反馈描述
					 * orderFormRecharge.setCore_status("CORE_SUC");
					 * 
					 * orderFormRecharge
					 * .setRecharge_orderform_status("TRADE_SUCCESS");// 订单状态
					 * OrderFormRecharge isFalgFormRecharge; isFalgFormRecharge
					 * = centerDao .selectOrderFromRechargeByOrderId(noOrder);
					 * System.out.println(isFalgFormRecharge
					 * .getRecharge_orderform_status()); if
					 * (isFalgFormRecharge.getRecharge_orderform_status()
					 * .equals("TRADE_SUCCESS")) { rtnMap.put("rescode",
					 * Consts.SUCCESS_CODE); rtnMap.put("resmsg",
					 * "此订单已更新回调成功。"); } else {
					 * centerDao.updateOrderFromRecharge(orderFormRecharge); //
					 * 更新主账户信息 String transCode = "E330032"; Map<String, Object>
					 * coreMap = new HashMap<String, Object>();
					 * coreMap.put("moneyOrder", moneyOrder);
					 * coreMap.put("userId", userId); coreMap.put("applyId",
					 * isFalgFormRecharge.getId()); // 构建json字符串 String jsonStr;
					 * jsonStr = CommonUtil.constructJsonStr(transCode, null,
					 * coreMap); String rtnStr =
					 * CommonUtil.getCoreValue(jsonStr); JSONObject jsonObject =
					 * JSONObject.fromObject(rtnStr); rescode =
					 * jsonObject.getString("rescode"); if
					 * (rescode.equals(Consts.SUCCESS_CODE)) {
					 * rtnMap.put("rescode", Consts.SUCCESS_CODE);
					 * rtnMap.put("resmsg", Consts.SUCCESS_DESCRIBE); } else {
					 * rtnMap.put("rescode", Consts.ERROR_CODE);
					 * rtnMap.put("resmsg", "更新用户主账户信息失败！"); } }
					 */
				}
			} else {
				System.out.println(
						"========================LLPAYSELECT FAILD,IN UPDATE ORDER!===========================");
				// 更新临时表订单信息
				OrderFormRecharge orderFormRecharge = new OrderFormRecharge();
				orderFormRecharge.setOrderform_id(noOrder);
				orderFormRecharge.setOrder_id(null);
				orderFormRecharge.setBack_time(new Date());// 反馈时间
				orderFormRecharge.setUpdate_time(new Date()); // 更新时间
				orderFormRecharge.setReceive_message(null);// 返回报文
				orderFormRecharge.setBack_commen("连连支付-支付失败");// 反馈描述
				orderFormRecharge.setCore_status("CORE_FAIL");

				orderFormRecharge.setRecharge_orderform_status("TRADE_FAIL");// 订单状态

				OrderFormRecharge isFalgFormRecharge;
				isFalgFormRecharge = centerDao.selectOrderFromRechargeByOrderId(noOrder);
				System.out.println(isFalgFormRecharge.getRecharge_orderform_status());
				if (isFalgFormRecharge.getRecharge_orderform_status().equals("TRADE_SUCCESS")) {
					rtnMap.put("rescode", Consts.SUCCESS_CODE);
					rtnMap.put("resmsg", "此订单已更新回调成功。");
				} else {
					System.out.println("==================BEGIN UPDATE===================");
					centerDao.updateOrderFromRecharge(orderFormRecharge);
				}
			}
		} catch (Exception e) {
			rtnMap.put("rescode", Consts.ERROR_CODE);
			rtnMap.put("resmsg", e.getMessage());
		}

		return rtnMap;
	}

	/**
	 * 查询是否支持该银行
	 */
	@Override
	public Map<String, Object> queryBankIdByBankCode(Map<String, Object> requestMap) {
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		/*
		 * Bank bank = this.userCardDao.queryBankInfoByBankCode(requestMap);
		 * if(bank!=null){ rtnMap.put("isExist", true); }else{
		 * rtnMap.put("isExist", false); }
		 */
		Integer id = this.userCardDao.queryBankIdByBankCode(requestMap);
		if (id != null) {
			Bank bank = this.userCardDao.queryBankInfoByBankCode(requestMap);
			rtnMap.put("payPlatformId", bank.getPay_platform_id());
			rtnMap.put("isExist", true);
		} else {
			rtnMap.put("isExist", false);
		}
		return rtnMap;
	}

	/**
	 * 更新用户回款卡号表城市省份信息
	 */
	@Override
	public void updateUserCardCityAndProvince(UserRecePayCard userCardPayCard) {
		this.userCardDao.updateUserCardCityAndProvince(userCardPayCard);
	}

	/**
	 * 连连核心回调
	 */
	@Override
	public Map<String, Object> coreLLPayNotify(Map<String, Object> requestMap) throws Exception {
		System.out.println("====进入方法coreLLPayNotify========");
		Map<String, Object> resultMap = new HashMap<String, Object>();

		String bindingReqNum = requestMap.get("bindingReqNum").toString();
		String payFlag = requestMap.get("payFlay") == null ? null : requestMap.get("payFlay").toString();

		String noAgree = requestMap.get("noAgree").toString();
		String moneyOrder = requestMap.get("moneyOrder").toString();
		String oidPayBill = requestMap.get("oidPayBill").toString();
		String reqStr = requestMap.get("reqStr").toString();

		String transCode = "E330033";
		Map<String, Object> coreMap = new HashMap<String, Object>();

		coreMap.put("bindingReqNum", bindingReqNum);
		coreMap.put("moneyOrder", moneyOrder);
		coreMap.put("oidPayBill", oidPayBill);
		coreMap.put("reqStr", reqStr);

		if (StringUtils.isNotBlank(noAgree)) {
			coreMap.put("noAgree", noAgree);
		}
		if (StringUtils.isNotBlank(payFlag)) {
			coreMap.put("payFlag", payFlag);
		}

		String jsonStr = CommonUtil.constructJsonStr(transCode, null, coreMap);
		String rtnStr = CommonUtil.getCoreValue(jsonStr);
		String userId = "";
		try {
			// 如果核心访问失败 返回连连成功（不需要连连继续回调）
			JSONObject jsonObject = JSONObject.fromObject(rtnStr);
			resultMap.put("rescode", jsonObject.getString("rescode"));
			resultMap.put("resmsg_cn", jsonObject.getString("resmsg"));
			resultMap.put("userId", jsonObject.getString("userId"));
			userId = jsonObject.getString("userId");
		} catch (Exception e) {
			resultMap.put("rescode", Consts.SUCCESS_CODE);
			resultMap.put("resmsg", Consts.SUCCESS_DESCRIBE);
		}

		return resultMap;
	}

	/**
	 * 保存银行卡解绑卡申请表
	 */
	@Override
	public ResultDTO addUnbindingCardApply(Map<String, Object> requestMap,String logInfo) throws Exception {

		String idCard = requestMap.get("idCard").toString();
		String userId = requestMap.get("userId").toString();


		List<UserRecePayCard> cardList = this.userCardDao.queryUserCardInfoByUserId(requestMap);

		// 判断用户是否进行绑卡
		if (null == cardList || cardList.size() == 0) {
			logger.info(logInfo+" 您还未绑定银行卡!");
			return new ResultDTO(ResultCode.FAILED,Message.CnDescriptionExpression.BINGINGCARD_NOT_EXIST);
		}

		// 判断是否有正在申请的解绑银行卡申请审核
		requestMap.put("processingStatus", "0");
		requestMap.put("userId", userId);

		UnbindingCardApply unbindingCardApply = this.userCardDao.queryProcessingUnbindingApply(requestMap);

		if (unbindingCardApply != null) {
			logger.info(logInfo+" 当前银行卡已经提交过解绑申请，请耐心等待工作人员审核!");
			return new ResultDTO(ResultCode.FAILED,Message.CnDescriptionExpression.UNBINDINGCARD_APPLY_EXIST);
		}

		// 判断身份证输入是否正确
		UserInfo userinfo = userDao.getUserInfo(userId);
		String userIdCard = userinfo.getId_card();

		if (!idCard.equals(userIdCard)) {
			logger.info(logInfo+" 验证信息与账户信息不符，请确认后重新输入!");
			return new ResultDTO(ResultCode.FAILED,Message.CnDescriptionExpression.IDCARD_ERROR);
		}

		// 判断账户余额是否为空（可用余额，提现中金额，冻结金额，活期在投金额，活期在投收益，定期在投金额）
		String transCode = "E330005";
		// 取得产品列表
		List<Finance> financeList = this.assetsDao.getFinanceList();

		StringBuffer productType = new StringBuffer();
		// 设置产品类型
		if (financeList == null || financeList.size() == 0) {
			productType.append("");
		} else {
			for (int i = 0; i < financeList.size(); i++) {
				Finance finance = financeList.get(i);
				productType.append(finance.getId());

				if (i != financeList.size() - 1) {
					productType.append(", ");
				}
			}
		}

		Map<String, Object> pageModelForWallet = new HashMap<String, Object>();

		pageModelForWallet.put("userId", userId); // 用户id
		// 产品类型：101 e计划(90天)，102 e贷通，103 涨薪宝, 104 e计划(365天),多个产品之间用英文【,】进行分隔
		pageModelForWallet.put("productType", productType.toString());

		// 构建json字符串
		String jsonStr = CommonUtil.constructJsonStr(transCode, userId, pageModelForWallet);

		// 调用核心接口
		String rtnStr = CommonUtil.getCoreValue(jsonStr);
		JSONObject jsonObject = JSONObject.fromObject(rtnStr);
		// rescode = "00000"
		if (Consts.SUCCESS_CODE.equals(jsonObject.get("rescode"))) {

			// 投资资产合计
			BigDecimal investmentAssets = BigDecimal.ZERO.setScale(2);
			// 现金资产合计
			BigDecimal cashAssets = BigDecimal.ZERO.setScale(2);
			// 账户总资产
			BigDecimal accountTotalAssets = BigDecimal.ZERO.setScale(2);
			// 账户可用余额
			BigDecimal balanceMoney = BigDecimal.ZERO.setScale(2);
			// 提现中冻结金额
			BigDecimal cashInMoney = BigDecimal.ZERO.setScale(2);
			// 还款中冻结金额
			BigDecimal repayFrozen = BigDecimal.ZERO.setScale(2);
			// 预计收益
			BigDecimal expectAmount = BigDecimal.ZERO.setScale(2);

			// 投资资产明细
			JSONArray jsonArr = jsonObject.getJSONArray("list");
			if (jsonArr != null && jsonArr.size() > 0) {
				for (int i = 0; i < jsonArr.size(); i++) {
					JSONObject jsonObj = jsonArr.getJSONObject(i);
					investmentAssets = investmentAssets
							.add(new BigDecimal(jsonObj.getString("productAssets")).setScale(2, BigDecimal.ROUND_DOWN));
					if (!jsonObj.getString("expectedAmount").equals("")
							&& !jsonObj.getString("expectedAmount").equals("null")) {
						expectAmount = expectAmount.add(
								new BigDecimal(jsonObj.getString("expectedAmount")).setScale(2, BigDecimal.ROUND_DOWN));
					}
				}
			}

			balanceMoney = new BigDecimal(jsonObject.getString("acctBalance")).setScale(2, BigDecimal.ROUND_DOWN);
			cashInMoney = new BigDecimal(jsonObject.getString("drawalFrozen")).setScale(2, BigDecimal.ROUND_DOWN);
			repayFrozen = new BigDecimal(jsonObject.getString("repayFrozen")).setScale(2, BigDecimal.ROUND_DOWN);

			cashAssets = balanceMoney.add(cashInMoney).add(repayFrozen);
			accountTotalAssets = investmentAssets.add(cashAssets);

			// 判断总资产是否为0
			if (accountTotalAssets.compareTo(BigDecimal.ZERO) > 0) {
				return new ResultDTO(ResultCode.FAILED,Message.CnDescriptionExpression.ACCT_BALANCE_MORE_THAN_ZERO);
			}

		} else {
			logger.info(logInfo+"=====核心接口调用异常=====");
			logger.info(logInfo+"核心接口：" + transCode);
			logger.info(logInfo+"rescode：" + jsonObject.getString("rescode") + "；  resmsg：" + jsonObject.getString("resmsg"));
			return new ResultDTO(ResultCode.FAILED,Message.CnDescriptionExpression.BUSINESSE_ERROR);
		}

		// 插入数据库数据
		UnbindingCardApply newApply = new UnbindingCardApply();
		newApply.setUser_id(Long.valueOf(userId));
		newApply.setCard_number(cardList.get(0).getCard_number());
		newApply.setLlpay_noagree(cardList.get(0).getLlpay_no_agree());
		newApply.setCreate_per(userId);
		newApply.setProcessing_status("0");

		this.userCardDao.addUnbindingCardApply(newApply);

		Map<String,Object> resMap=new HashMap<String,Object>();
		UserRecePayCard userRecePayCard = cardList.get(0);
		resMap.put("userRecePayCard", userRecePayCard);
		resMap.put("newApply", newApply);
		if (newApply.getId() != null) {
			ResultDTO resultDTO=new ResultDTO(ResultCode.SUCCESS,"您已成功申请解绑银行卡，工作人员将于3个工作日内帮您处理完成");
			resultDTO.setRecord(resMap);
			return resultDTO;
		}

		ResultDTO resultDTO=new ResultDTO(ResultCode.FAILED);
		resultDTO.setRecord(resMap);

		return resultDTO;
	}

	/**
	 * 解绑银行卡-临时提供给运营的数据
	 */
	@Override
	public Map<String, Object> unbdingUserCard(String userId) throws Exception {
		Map<String, Object> returnMap = new HashMap<String, Object>();
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", userId);

		// 查询用户的绑定银行卡信息
		List<UserRecePayCard> bingingCardList = this.userCardDao.queryUserCardInfoByUserId(paramMap);

		if (bingingCardList == null || bingingCardList.size() == 0) {
			returnMap.put("rescode", Consts.ERROR_CODE);
			returnMap.put("resmsg", "用户没有绑定的银行卡");
			return returnMap;
		}

		// 调用连连解绑银行卡
		UserRecePayCard userBindCard = bingingCardList.get(0);

		Map<String, String> bankCardUnbingReqMap = new HashMap<String, String>();
		bankCardUnbingReqMap.put("userId", String.valueOf(userBindCard.getUser_id()));
		bankCardUnbingReqMap.put("payType", "D");
		bankCardUnbingReqMap.put("noAgree", userBindCard.getLlpay_no_agree());

		Map<String, String> bcuRtnMap = LLPayThridPartyFunctionUtil.bankCardUnbind(bankCardUnbingReqMap);

		String rspCd = bcuRtnMap.get("rescode");
		String rspMsg = bcuRtnMap.get("resmsg_cn");

		if (rspCd.equals("0000")) {
			// 解绑银行卡成功 更新数据
			userBindCard.setLlpay_no_agree("");
			userBindCard.setIs_binding('N');
			userBindCard.setIs_valid('N');
			userBindCard.setLlpay_oid_paybill("");
			userBindCard.setUpdate_per(userId);
			this.userCardDao.updateUserBankCardInfoByIdAll(userBindCard);
			returnMap.put("rescode", Consts.SUCCESS_CODE);
			returnMap.put("resmsg", "成功");

		} else {
			returnMap.put("rescode", Consts.ERROR_CODE);
			returnMap.put("resmsg", rspMsg);
			return returnMap;
		}
		return returnMap;
	}

	/**
	 * 解绑银行卡-连连接口直接调用 临时提供给运营的接口
	 */
	@Override
	public Map<String, Object> llpayBankCardUnbind(String userId, String noAgree) throws Exception {
		Map<String, Object> returnMap = new HashMap<String, Object>();

		Map<String, String> bankCardUnbingReqMap = new HashMap<String, String>();
		bankCardUnbingReqMap.put("userId", userId);
		bankCardUnbingReqMap.put("payType", "D");
		bankCardUnbingReqMap.put("noAgree", noAgree);

		Map<String, String> bcuRtnMap = LLPayThridPartyFunctionUtil.bankCardUnbind(bankCardUnbingReqMap);

		String rspCd = bcuRtnMap.get("rescode");
		String rspMsg = bcuRtnMap.get("resmsg_cn");

		if (rspCd.equals("0000")) {
			returnMap.put("rescode", Consts.SUCCESS_CODE);
			returnMap.put("resmsg_cn", "解绑成功");
		} else {
			returnMap.put("rescode", Consts.ERROR_CODE);
			returnMap.put("resmsg_cn", rspMsg);
		}
		return returnMap;
	}

	/**
	 * 查询当月剩余快速提现次数
	 */
	@Override
	public UserQuickWithdraw queryUserQuickCountByIdAndMonth(Map<String, Object> paramsMap) {

		return userCardDao.queryUserQuickCountByIdAndMonth(paramsMap);
	}

	/**
	 * 掌上汇通鉴权通道
	 * 
	 * @return
	 * @throws Exception
	 * @throws NumberFormatException
	 * @throws PaypalmException
	 */
	/*
	 * public Map<String,Object> zshtBankCardAndPhoneCheck(Long userId,String
	 * bankCard,String cardUserName,String idNo,String cardPhone) throws
	 * NumberFormatException, Exception{
	 * 
	 * Map<String,Object> checkCardReqMap = new HashMap<String,Object>();
	 * Map<String,Object> rtnMap = new HashMap<String,Object>(); //判断卡号是否进行过鉴权操作
	 * checkCardReqMap.put("userId", userId); checkCardReqMap.put("cardNumber",
	 * bankCard); checkCardReqMap.put("phoneNum", cardPhone);
	 * checkCardReqMap.put("idNo", idNo); checkCardReqMap.put("cardUserName",
	 * cardUserName); UserZSHTCheckCard userCheckCard =
	 * this.userCardDao.queryZSHTBankCardCheck(checkCardReqMap); String
	 * checkFlag = "N"; if(userCheckCard!=null){ checkFlag = "Y";
	 * rtnMap.put("checkFlag", checkFlag); return rtnMap; } //判断当日鉴权次数是否超限
	 * Integer zshtCheckBankCodeCount =
	 * Integer.parseInt(rateRisesCouponsService.findParamValueByName(
	 * "zsht_check_bank_count"));
	 * 
	 * ZSHTCheckBankCountInfo checkBankCardInfo =
	 * this.userCardDao.queryUserCurrentCheckBankInfo(checkCardReqMap);
	 * 
	 * if(checkBankCardInfo!=null){
	 * if(checkBankCardInfo.getCheck_count()>=zshtCheckBankCodeCount){
	 * rtnMap.put("checkFlag", checkFlag); rtnMap.put("checkDesc",
	 * "手机号码输错超过"+zshtCheckBankCodeCount+"次，请明日再充值！"); return rtnMap; } }
	 * 
	 * Map<String, String> requestMap = new HashMap<String, String>();
	 * requestMap.put("bankCard", bankCard); requestMap.put("cardUserName",
	 * cardUserName); requestMap.put("idNo", idNo); requestMap.put("cardPhone",
	 * cardPhone);
	 * 
	 * Map<String,String> thridResMap
	 * =ZSHTPayThridPartyFunctionUtil.bankCardAndPhoneCheck(requestMap);
	 * 
	 * if (thridResMap == null ||
	 * "sysException".equals(thridResMap.get("rescode"))) {
	 * 
	 * rtnMap.put("checkFlag", checkFlag); rtnMap.put("checkDesc",
	 * thridResMap.get("resmsg_cn")); return rtnMap; } else if
	 * ("BusinessException".equals(thridResMap.get("rescode"))) {
	 * 
	 * rtnMap.put("checkFlag", checkFlag); rtnMap.put("checkDesc",
	 * thridResMap.get("resmsg_cn")); return rtnMap; }
	 * 
	 * String rescode = thridResMap.get("rescode"); String resmsg =
	 * thridResMap.get("resmsg_cn");
	 * 
	 * if("00".equals(rescode)){ checkFlag = "Y"; //保存鉴权相关信息 userCheckCard = new
	 * UserZSHTCheckCard(); userCheckCard.setUser_id(userId);
	 * userCheckCard.setCard_number(bankCard);
	 * userCheckCard.setPhone_num(cardPhone);
	 * userCheckCard.setCard_user_name(cardUserName);
	 * userCheckCard.setId_no(idNo);
	 * 
	 * this.userCardDao.insertZSHTBankCardCheck(userCheckCard);
	 * 
	 * } rtnMap.put("checkFlag", checkFlag); rtnMap.put("checkDesc", resmsg);
	 * 
	 * 
	 * //不论成功失败都要保存鉴权次数信息 if(checkBankCardInfo!=null){
	 * checkBankCardInfo.setCheck_count(checkBankCardInfo.getCheck_count()+1);
	 * this.userCardDao.updateUserCurrentCheckBankInfo(checkBankCardInfo);
	 * }else{ checkBankCardInfo = new ZSHTCheckBankCountInfo();
	 * checkBankCardInfo.setUser_id(Integer.parseInt(userId.toString()));
	 * checkBankCardInfo.setCheck_count(1);
	 * this.userCardDao.insertUserCurrentCheckBankInfo(checkBankCardInfo); }
	 * return rtnMap; }
	 */
	/**
	 * 随机生成订单
	 * 
	 * @return
	 */
	public String createNoOrder(String title) {
		Date now = new Date();
		SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		String currTime = outFormat.format(now);

		String strReq = currTime;
		Random random = new Random();
		String result = "";
		for (int i = 0; i < 8; i++) {
			result += random.nextInt(10);
		}

		String requestNo = title + strReq + result;
		return requestNo;
	}

	@Override
	public String queryNextWorkingDay(String currentDay) {
		return this.userCardDao.queryNextWorkingDay(currentDay);
	}

	@Override
	public Long queryWorkingDayByCurrentDay(String currentDay) {
		return this.userCardDao.queryWorkingDayByCurrentDay(currentDay);
	}

	/**
	 * 失败发送短信
	 * 
	 * @throws Exception
	 */
	@Override
	public void sendErrorMessage(String userId, String content) throws Exception {
		String smChannel = this.rateRisesCouponsService.findParamValueByName("send_sms_channel");
		User user = this.userDao.getUserDetail(userId);
		Map<String, String> semParams = new HashMap<String, String>();
		// 查询短信渠道
		semParams.put("content", content);
		semParams.put("send_sms_channel", smChannel);
		semParams.put("mobileListParams", user.getMobile());

		Map<String, String> resultMap = ZSHTPayThridPartyFunctionUtil.sendErrorMessage(semParams);
		String rescode = resultMap.get("rescode");
	}

	/**
	 * 根据用户ID查询快速提现金额
	 */
	@Override
	public UserQuickWithdraw queryUserQuickCountByUserId(Map<String, Object> paramsMap) {
		return this.userCardDao.queryUserQuickCountByUserId(paramsMap);
	}

	/**
	 * 查询银行信息
	 */
	@Override
	public Bank queryBankInfoByBankCode(Map<String, Object> paramMap) {
		Bank bank = userCardDao.queryBankInfoByBankCode(paramMap);
		return bank;
	}
}
